<!--
 * @Author: xiaolong.luo@flowportal xiaolong.luo8888
 * @Date: 2024-04-26 15:37:58
 * @LastEditors: xiaolong.luo@flowportal xiaolong.luo8888
 * @LastEditTime: 2024-05-16 09:32:58
 * @FilePath: \v2-project\src\views\user\Login.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <van-form @submit="onSubmit">
    <van-field
      v-model="account"
      name="account"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="password"
      type="pwd"
      name="password"
      label="密码"
      placeholder="密码"
    />
    <div style="margin: 16px">
      <van-button block type="info" native-type="submit">登录</van-button>
    </div>
  </van-form>
</template>

<script>
import { auth } from "@/api/bpm/auth";

export default {
  name: "LoginPage",
  data() {
    return {
      account: "admin",
      password: "",
    };
  },
  methods: {
    async onSubmit(values) {
      const res = await auth(values).catch(() => {})
      console.log(res);
      if (res.success) {
        await this.$store.dispatch("auth/setAuthTokenAsync", res.token)
        this.$router.push("/news")
      } else {
        this.$toast(res.errorMessage)
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
